<!-- 商品中心 - 商品列表  -->
<template>
<!--  <doc-alert title="【商品】商品 SPU 与 SKU" url="https://doc.iocoder.cn/mall/product-spu-sku/" />-->

  <!-- 搜索工作栏 -->
  <ContentWrap>
    <el-form
      ref="queryFormRef"
      :inline="true"
      :model="queryParams"
      class="-mb-15px"
      label-width="68px"
    >
      <el-form-item label="商品名称" prop="name">
        <el-input
          v-model="queryParams.name"
          class="!w-240px"
          clearable
          placeholder="请输入商品名称"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="商品分类" prop="categoryId">
        <el-cascader
          v-model="queryParams.categoryId"
          :options="categoryList"
          :props="defaultProps"
          class="w-1/1"
          clearable
          filterable
          placeholder="请选择商品分类" 
        />
      </el-form-item> -->
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker
          v-model="queryParams.createTime"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
          end-placeholder="结束日期"
          start-placeholder="开始日期"
          type="daterange"
          value-format="YYYY-MM-DD HH:mm:ss"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery">
          <Icon class="mr-5px" icon="ep:search" />
          搜索
        </el-button>
        <el-button @click="resetQuery">
          <Icon class="mr-5px" icon="ep:refresh" />
          重置
        </el-button>
        <el-button @click="handleRefresh" type="info" plain>
          <Icon class="mr-5px" icon="ep:refresh-right" />
          刷新数据
        </el-button>
        <el-button
          v-hasPermi="['product:spu:create']"
          plain
          type="primary"
          @click="openForm(undefined)"
        >
          <Icon class="mr-5px" icon="ep:plus" />
          新增
        </el-button>
        <el-button
          v-hasPermi="['product:spu:export']"
          :loading="exportLoading"
          plain
          type="success"
          @click="handleExport"
        >
          <Icon class="mr-5px" icon="ep:download" />
          导出
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-tabs v-model="queryParams.tabType" @tab-click="handleTabClick">
      <el-tab-pane
        v-for="item in tabsData"
        :key="item.type"
        :label="item.name + '(' + item.count + ')'"
        :name="item.type"
      />
    </el-tabs>
    <el-table v-loading="loading" :data="list">
      <el-table-column type="expand">
        <template #default="{ row }">
          <el-form class="spu-table-expand" label-position="left">
            <el-row>
              <el-col :span="24">
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="商品分类:">
                      <span>{{ formatCategoryName(row.categoryId) }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="市场价:">
                      <span>{{ fenToYuan(row.marketPrice) }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="成本价:">
                      <span>{{ fenToYuan(row.costPrice) }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="浏览量:">
                      <span>{{ row.browseCount }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="虚拟销量:">
                      <span>{{ row.virtualSalesCount }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="商品编号" min-width="140" prop="id" />
      <el-table-column label="商品信息" min-width="300">
        <template #default="{ row }">
          <div class="flex">
            <el-image
              fit="cover"
              :src="row.picUrl"
              class="flex-none w-50px h-50px"
              @click="imagePreview(row.picUrl)"
            />
            <div class="ml-4 overflow-hidden">
              <el-tooltip effect="dark" :content="row.name" placement="top">
                <div>
                  {{ row.name }}
                </div>
              </el-tooltip>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="价格" min-width="160" prop="price">
        <template #default="{ row }"> ¥ {{ fenToYuan(row.price) }}</template>
      </el-table-column>
      <el-table-column align="center" label="销量" min-width="90" prop="salesCount" />
      <el-table-column align="center" label="库存" min-width="90" prop="stock" />
      <el-table-column align="center" label="排序" min-width="70" prop="sort" />
      <el-table-column align="center" label="销售状态" min-width="80">
        <template #default="{ row }">
          <template v-if="row.status >= 0">
            <el-switch
              v-model="row.status"
              :active-value="1"
              :inactive-value="0"
              active-text="上架"
              inactive-text="下架"
              inline-prompt
              @change="handleStatusChange(row)"
            />
          </template>
          <template v-else>
            <el-tag type="info">回收站</el-tag>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        :formatter="dateFormatter"
        align="center"
        label="创建时间"
        prop="createTime"
        width="180"
      />
      <el-table-column align="center" fixed="right" label="操作" min-width="200">
        <template #default="{ row }">
          <el-button link type="primary" @click="openDetail(row.id)"> 详情 </el-button>
          <el-button
            v-hasPermi="['product:spu:update']"
            link
            type="primary"
            @click="openForm(row.id)"
          >
            修改
          </el-button>
          <template v-if="queryParams.tabType === 4">
            <el-button
              v-hasPermi="['product:spu:delete']"
              link
              type="danger"
              @click="handleDelete(row.id)"
            >
              删除
            </el-button>
            <el-button
              v-hasPermi="['product:spu:update']"
              link
              type="primary"
              @click="handleStatus02Change(row, ProductSpuStatusEnum.DISABLE.status)"
            >
              恢复
            </el-button>
          </template>
          <template v-else>
            <el-button
              v-hasPermi="['product:spu:update']"
              link
              type="danger"
              @click="handleStatus02Change(row, ProductSpuStatusEnum.RECYCLE.status)"
            >
              回收
            </el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      v-model:limit="queryParams.pageSize"
      v-model:page="queryParams.pageNo"
      :total="total"
      @pagination="getList"
    />
  </ContentWrap>
</template>
<script lang="ts" setup>
import { TabsPaneContext } from 'element-plus'
import { createImageViewer } from '@/components/ImageViewer'
import { dateFormatter } from '@/utils/formatTime'
import { handleTree, treeToString } from '@/utils/tree'
import { ProductSpuStatusEnum } from '@/utils/constants'
import { fenToYuan } from '@/utils'
import download from '@/utils/download'
import * as ProductSpuApi from '@/api/mall/product/carrent'
import * as ProductCategoryApi from '@/api/mall/product/category'

defineOptions({ name: 'ProductCarShell' })

const message = useMessage() // 消息弹窗
const route = useRoute() // 路由
const { t } = useI18n() // 国际化
const router = useRouter() // 路由
const { push } = router // 路由跳转

const loading = ref(false) // 列表的加载中
const exportLoading = ref(false) // 导出的加载中
const total = ref(0) // 列表的总页数
const list = ref<ProductSpuApi.Spu[]>([]) // 列表的数据
// tabs 数据
const tabsData = ref([
  {
    name: '出售中',
    type: 0,
    count: 0
  },
  {
    name: '仓库中',
    type: 1,
    count: 0
  },
  {
    name: '已售罄',
    type: 2,
    count: 0
  },
  {
    name: '警戒库存',
    type: 3,
    count: 0
  },
  
  {
    name: '回收站',
    type: 4,
    count: 0
  }
])

// 车辆售卖分类ID常量
const CAR_SELL_CATEGORY_ID = 85

// 获取车辆售卖相关的所有分类ID（包括父分类和子分类）
const getCarSellCategoryIds = (categoryList: any[]): number[] => {
  const categoryIds: number[] = []

  // 首先添加车辆售卖主分类ID
  categoryIds.push(CAR_SELL_CATEGORY_ID)

  // 查找所有以85为父分类的子分类
  const findChildCategories = (categories: any[], parentId: number) => {
    categories.forEach(category => {
      if (category.parentId === parentId) {
        categoryIds.push(category.id)
        console.log(`找到车辆售卖子分类: [${category.id}] ${category.name}`)
        // 递归查找子分类的子分类
        findChildCategories(categories, category.id)
      }
    })
  }

  findChildCategories(categoryList, CAR_SELL_CATEGORY_ID)

  console.log('车辆售卖相关分类ID列表:', categoryIds)
  return categoryIds
}

// 检查商品是否属于车辆售卖分类
const isCarSellProduct = (productCategoryId: number, carSellCategoryIds: number[]): boolean => {
  return carSellCategoryIds.includes(productCategoryId)
}

const queryParams = ref({
  pageNo: 1,
  pageSize: 10,
  tabType: 0,
  name: '',
  categoryId: undefined as number | undefined, // 不设置分类ID，在前端过滤
  createTime: undefined
}) // 查询参数
const queryFormRef = ref() // 搜索的表单Ref

// 缓存所有车辆租赁商品数据，避免重复请求
let allVehicleProducts: any[] = []

// 车辆售卖相关的所有分类ID列表
let carSellCategoryIds: number[] = []

/**
 * 强制更新缓存数据（在商品操作后调用）
 */
const forceUpdateCache = async () => {
  try {
    console.log('=== 强制更新缓存数据 ===')

    // 分批获取所有商品数据
    let allProducts: any[] = []
    let pageNo = 1
    const pageSize = 100

    while (true) {
      const data = await ProductSpuApi.getSpuPage({ pageNo, pageSize })
      if (data && data.list && data.list.length > 0) {
        allProducts = allProducts.concat(data.list)
        if (data.list.length < pageSize) {
          break
        }
        pageNo++
      } else {
        break
      }
    }

    // 过滤车辆售卖相关的商品
    allVehicleProducts = allProducts.filter((spu: any) =>
      isCarSellProduct(spu.categoryId, carSellCategoryIds)
    )

    console.log('缓存已更新，总商品数量:', allProducts.length)
    console.log('车辆售卖商品数量:', allVehicleProducts.length)

    // 重新计算tabs统计
    calculateTabsCount(allVehicleProducts)
  } catch (error) {
    console.error('强制更新缓存失败:', error)
  }
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    console.log('正在获取商品列表，查询参数:', queryParams.value)
    const data = await ProductSpuApi.getSpuPage(queryParams.value)
    console.log('API返回的数据:', data)

    if (data && data.list) {
      // 判断是否有条件查询（除了tabType之外的查询条件）
      const hasSearchConditions = queryParams.value.name || queryParams.value.createTime

      let vehicleProducts: any[]

      if (hasSearchConditions) {
        console.log('🔍 检测到条件查询，过滤车辆售卖相关商品')
        console.log('查询条件:', {
          name: queryParams.value.name,
          createTime: queryParams.value.createTime
        })

        // 有条件查询时，过滤API返回的数据
        vehicleProducts = data.list.filter((spu: any) =>
          isCarSellProduct(spu.categoryId, carSellCategoryIds)
        )
      } else {
        console.log('📋 无条件查询，过滤车辆售卖相关商品')

        // 过滤车辆售卖相关的商品
        vehicleProducts = data.list.filter((spu: any) =>
          isCarSellProduct(spu.categoryId, carSellCategoryIds)
        )

        // 如果缓存为空，则更新缓存（初始化时）
        if (allVehicleProducts.length === 0) {
          allVehicleProducts = vehicleProducts
          console.log('初始化缓存数据，车辆售卖商品数量:', vehicleProducts.length)
        }
      }

      console.log('=== getList 调试信息 ===')
      console.log('API返回的原始数据数量:', data.list.length)
      console.log('车辆售卖相关分类ID:', carSellCategoryIds)
      console.log('过滤后的车辆售卖商品数量:', vehicleProducts.length)
      console.log('是否有条件查询:', hasSearchConditions)

      // 显示所有商品的分类ID分布
      const categoryDistribution = {}
      data.list.forEach((spu: any) => {
        categoryDistribution[spu.categoryId] = (categoryDistribution[spu.categoryId] || 0) + 1
      })
      console.log('所有商品的分类ID分布:', categoryDistribution)

      if (vehicleProducts.length > 0) {
        console.log('车辆售卖商品详情:', vehicleProducts.map((spu: any) => ({
          id: spu.id,
          name: spu.name,
          status: spu.status,
          stock: spu.stock,
          categoryId: spu.categoryId
        })))
      } else {
        console.warn('⚠️ 没有找到车辆售卖商品！')
        console.log('💡 可能的原因：')
        console.log('  1. 车辆售卖相关分类下没有商品')
        console.log('  2. 商品状态不符合当前tab筛选条件')
        console.log('  3. 搜索条件过于严格')
        console.log('  4. 分类ID配置有误')
      }

      // 根据当前选中的tab类型过滤显示的商品
      const tabType = queryParams.value.tabType
      console.log('当前tab类型:', tabType)

      if (hasSearchConditions) {
        console.log('条件查询：使用API返回的数据进行tab过滤')

        // 有条件查询时，使用API返回的数据进行tab过滤
        const filteredList = vehicleProducts.filter((spu: any) => {
          switch (tabType) {
            case 0: // 出售中
              return spu.status === 1 && spu.stock > 0
            case 1: // 仓库中
              return spu.status === 0
            case 2: // 已售罄
              return spu.status === 1 && spu.stock <= 0
            case 3: // 警戒库存
              return spu.stock <= 5 && spu.stock > 0
            case 4: // 回收站
              return spu.status === -1
            default:
              return true
          }
        })

        list.value = filteredList
        total.value = data.total || filteredList.length

        console.log('条件查询结果 - 过滤前:', vehicleProducts.length)
        console.log('条件查询结果 - 过滤后:', filteredList.length)
      } else {
        console.log('无条件查询：使用缓存数据进行tab过滤，缓存商品数量:', allVehicleProducts.length)

        // 无条件查询时，使用缓存数据进行tab过滤
        const filteredList = allVehicleProducts.filter((spu: any) => {
          switch (tabType) {
            case 0: // 出售中
              return spu.status === 1 && spu.stock > 0
            case 1: // 仓库中
              return spu.status === 0
            case 2: // 已售罄
              return spu.status === 1 && spu.stock <= 0
            case 3: // 警戒库存
              return spu.stock <= 5 && spu.stock > 0
            case 4: // 回收站
              const isRecycled = spu.status === -1
              console.log('检查回收站商品:', {
                id: spu.id,
                name: spu.name,
                status: spu.status,
                categoryId: spu.categoryId,
                是否为回收状态: isRecycled
              })
              return isRecycled
            default:
              return true
          }
        })

        list.value = filteredList
        total.value = filteredList.length

        console.log('过滤后显示的商品数量:', filteredList.length)
        console.log('过滤后的商品列表:', filteredList.map((spu: any) => ({
          id: spu.id,
          name: spu.name,
          status: spu.status
        })))
      }

      console.log('=== getList 调试信息结束 ===')
    } else {
      console.warn('API返回空数据')
      list.value = []
      total.value = 0
      // 重置缓存和tabs统计
      allVehicleProducts = []
      tabsData.value.forEach(tab => {
        tab.count = 0
      })
    }
  } catch (error) {
    console.error('获取商品列表失败:', error)
    message.error('获取商品列表失败: ' + (error as Error).message)
    list.value = []
    total.value = 0
  } finally {
    loading.value = false
  }
}

/** 切换 Tab */
const handleTabClick = (tab: TabsPaneContext) => {
  queryParams.value.tabType = tab.paneName as number
  getList()
}

/**
 * 根据车辆租赁商品计算各个Tab的数量
 * @param vehicleProducts 车辆租赁商品列表
 */
const calculateTabsCount = (vehicleProducts: any[]) => {
  // 重置所有tab的计数
  tabsData.value.forEach(tab => {
    tab.count = 0
  })

  // 统计各个状态的商品数量
  vehicleProducts.forEach((spu: any) => {
    // 根据商品状态和库存情况分类统计
    if (spu.status === 1) { // 上架状态
      if (spu.stock > 0) {
        tabsData.value[0].count++ // 出售中
      } else {
        tabsData.value[2].count++ // 已售罄
      }
    } else if (spu.status === 0) { // 下架状态
      tabsData.value[1].count++ // 仓库中
    } else if (spu.status === -1) { // 回收站状态
      tabsData.value[4].count++ // 回收站
    }

    // 警戒库存的判断（假设库存小于等于5为警戒库存）
    if (spu.stock <= 5 && spu.stock > 0) {
      tabsData.value[3].count++ // 警戒库存
    }
  })

  console.log('车辆售卖商品统计:', {
    总数: vehicleProducts.length,
    出售中: tabsData.value[0].count,
    仓库中: tabsData.value[1].count,
    已售罄: tabsData.value[2].count,
    警戒库存: tabsData.value[3].count,
    回收站: tabsData.value[4].count
  })
}

/**
 * 刷新tabs统计数据（重新从服务器获取数据）
 */
const refreshTabsCount = async () => {
  try {
    // 分批获取所有商品数据来进行统计
    let allProducts: any[] = []
    let pageNo = 1
    const pageSize = 100 // 使用最大允许的页面大小

    while (true) {
      const data = await ProductSpuApi.getSpuPage({ pageNo, pageSize })
      if (data && data.list && data.list.length > 0) {
        allProducts = allProducts.concat(data.list)
        // 如果返回的数据少于pageSize，说明已经是最后一页
        if (data.list.length < pageSize) {
          break
        }
        pageNo++
      } else {
        break
      }
    }

    if (allProducts.length > 0) {
      // 过滤车辆售卖相关的商品并缓存
      allVehicleProducts = allProducts.filter((spu: any) =>
        isCarSellProduct(spu.categoryId, carSellCategoryIds)
      )

      console.log('=== 刷新tabs统计数据 ===')
      console.log('所有商品数量:', allProducts.length)
      console.log('车辆售卖相关分类ID:', carSellCategoryIds)
      console.log('车辆售卖商品数量:', allVehicleProducts.length)
      console.log('车辆售卖商品详情:', allVehicleProducts.map((spu: any) => ({
        id: spu.id,
        name: spu.name,
        status: spu.status,
        categoryId: spu.categoryId
      })))

      // 计算tabs数量
      calculateTabsCount(allVehicleProducts)
    }
  } catch (error) {
    console.error('刷新tabs统计数据失败:', error)
    // 如果出错，重置所有计数为0
    tabsData.value.forEach(tab => {
      tab.count = 0
    })
  }
}

/** 添加到仓库 / 回收站的状态 */
const handleStatus02Change = async (row: any, newStatus: number) => {
  try {
    // 二次确认
    const text = newStatus === ProductSpuStatusEnum.RECYCLE.status ? '加入到回收站' : '恢复到仓库'
    await message.confirm(`确认要"${row.name}"${text}吗？`)
    // 发起修改
    await ProductSpuApi.updateStatus({ id: row.id, status: newStatus })
    message.success(text + '成功')

    console.log('=== 回收操作完成，开始刷新数据 ===')
    // 强制更新缓存和tabs统计
    await forceUpdateCache()
    // 刷新当前显示的列表
    await getList()
    console.log('=== 数据刷新完成 ===')
  } catch {}
}

/** 更新上架/下架状态 */
const handleStatusChange = async (row: any) => {
  try {
    // 二次确认
    const text = row.status ? '上架' : '下架'
    await message.confirm(`确认要${text}"${row.name}"吗？`)
    // 发起修改
    await ProductSpuApi.updateStatus({ id: row.id, status: row.status })
    message.success(text + '成功')
    // 强制更新缓存和tabs统计
    await forceUpdateCache()
    // 刷新当前显示的列表
    await getList()
  } catch {
    // 异常时，需要重置回之前的值
    row.status =
      row.status === ProductSpuStatusEnum.DISABLE.status
        ? ProductSpuStatusEnum.ENABLE.status
        : ProductSpuStatusEnum.DISABLE.status
  }
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await ProductSpuApi.deleteSpu(id)
    message.success(t('common.delSuccess'))
    // 强制更新缓存和tabs统计
    await forceUpdateCache()
    // 刷新当前显示的列表
    await getList()
  } catch {}
}

/** 商品图预览 */
const imagePreview = (imgUrl: string) => {
  createImageViewer({
    urlList: [imgUrl]
  })
}

/** 搜索按钮操作 */
const handleQuery = () => {
  console.log('=== 执行搜索 ===')
  console.log('搜索参数:', queryParams.value)

  // 检查是否有条件查询
  const hasConditions = queryParams.value.name || queryParams.value.createTime
  console.log('是否有搜索条件:', hasConditions)

  if (queryParams.value.name) {
    console.log('搜索的商品名称:', queryParams.value.name)
  }
  if (queryParams.value.createTime) {
    console.log('搜索的创建时间:', queryParams.value.createTime)
  }

  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 刷新数据按钮操作 */
const handleRefresh = async () => {
  console.log('=== 手动刷新数据 ===')

  // 清空缓存，强制重新获取数据
  allVehicleProducts = []

  // 重新获取数据并刷新tabs统计
  await refreshTabsCount()
  await getList()

  message.success('数据刷新成功')
}

/** 新增或修改 */
const openForm = (id?: number) => {
  // 修改
  if (typeof id === 'number') {
    push({ name: 'ProductCarShellEdit', params: { id } })
    return
  }
  // 新增
  push({ name: 'ProductCarShellAdd' })
}

/** 查看商品详情 */
const openDetail = (id: number) => {
  push({ name: 'ProductCarShellDetail', params: { id } })
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await ProductSpuApi.exportSpu(queryParams.value)
    download.excel(data, '商品列表.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 获取分类的节点的完整结构 */
const categoryList = ref() // 分类树
const formatCategoryName = (categoryId: number) => {
  return treeToString(categoryList.value, categoryId)
}

/** 激活时 */
onActivated(async () => {
  console.log('=== 车辆售卖页面被激活 ===')

  // 检查是否有刷新标识
  const refreshParam = route.query.refresh
  if (refreshParam) {
    console.log('=== 检测到刷新标识，强制刷新数据 ===')

    // 清除路由参数中的刷新标识
    await router.replace({
      name: route.name!,
      query: { ...route.query, refresh: undefined }
    })

    // 强制刷新缓存和tabs统计
    await forceUpdateCache()

    // 刷新当前列表
    await getList()

    console.log('=== 车辆售卖页面数据强制刷新完成 ===')
  } else {
    console.log('=== 无刷新标识，仅刷新列表 ===')
    // 只刷新列表，不强制更新缓存
    await getList()
  }
})

/** 初始化 **/
onMounted(async () => {
  // 解析路由的 categoryId
  if (route.query.categoryId) {
    queryParams.value.categoryId = Number(route.query.categoryId)
  }

  // 先获得分类树，确保分类数据可用于过滤
  const data = await ProductCategoryApi.getCategoryList({})
  categoryList.value = handleTree(data, 'id', 'parentId')

  // 计算车辆售卖相关的所有分类ID
  carSellCategoryIds = getCarSellCategoryIds(data)

  // 显示分类配置信息（调试用）
  console.log('=== 车辆售卖页面 - 分类配置检查 ===')
  console.log('🔍 原始分类数据:')
  data.forEach((category: any) => {
    console.log(`  分类: [${category.id}] ${category.name} (父分类ID: ${category.parentId})`)
  })

  console.log('🔍 分类树结构:')
  categoryList.value.forEach((category: any) => {
    console.log(`  父分类: [${category.id}] ${category.name}`)
    if (category.children && category.children.length > 0) {
      category.children.forEach((child: any) => {
        console.log(`    └─ 子分类: [${child.id}] ${child.name}`)
      })
    }
  })

  // 检查车辆售卖分类是否存在
  const carSellCategory = data.find((cat: any) => cat.id === CAR_SELL_CATEGORY_ID)

  if (carSellCategory) {
    console.log('✅ 找到车辆售卖主分类:', carSellCategory)
    console.log('✅ 车辆售卖相关分类ID列表:', carSellCategoryIds)
  } else {
    console.warn('⚠️ 未找到车辆售卖分类（ID=85），请检查分类配置')
  }

  // 获得商品信息
  await refreshTabsCount() // 初始化时刷新tabs统计
  await getList()
})
</script>
<style lang="scss" scoped>
.spu-table-expand {
  padding-left: 42px;

  :deep(.el-form-item__label) {
    width: 82px;
    font-weight: bold;
    color: #99a9bf;
  }
}
</style>
